
-- if CFS is missing Sales_Star_Customer
select a.AddressNumber, b.SearchTypeCode from RD_DWCR.dbo.JDEARCMbyLineofBusines a, RD_DWCR.dbo.JDEABAddressBookMaster b 
where 
	a.AddressNumber=b.AddressNumber and  
	b.SearchTypeCode in ('CFS') and 
	a.AddressNumber not in 
	(SELECT [ShiptoNumber] 
	 FROM [RD_COMMON].[dbo].[Sales_Star_Customer])
order by a.AddressNumber DESC
--5990 records

/**
SELECT [AddressNumber]
  FROM [MicroStrategy_Views].[dbo].[Common_Star_AddressBook]
  WHERE [AddressNumber] IN (7130015,7130962,7131487,7138435,7147773)


SELECT [AddressNumber]
  FROM [RD_COMMON].dbo.Star_AddressBook
  WHERE [AddressNumber] IN (7130015,7130962,7131487,7138435,7147773)



SELECT [ShiptoNumber]
  FROM [RD_COMMON].[dbo].[Sales_Star_Customer]
  WHERE [ShiptoNumber] NOT IN (
  
  
(7130015,7130962,7131487,7138435,7147773)
  
  

SELECT [ShiptoNumber]
  FROM [RD_COMMON].[dbo].[Sales_Star_Customer]
  WHERE [ShiptoNumber] IN (7130015,7130962,7131487,7138435,7147773)



EXECUTE dbo.dba_indexDefrag_sp
              @executeSQL           = 1
            , @printCommands        = 1
            , @debugMode            = 1
            , @printFragmentation   = 1
            , @forceRescan          = 1
            , @maxDopRestriction    = 1
            , @minPageCount         = 8
            , @maxPageCount         = NULL
            , @minFragmentation     = 1
            , @rebuildThreshold     = 30
            , @defragDelay          = '00:00:05'
            , @defragOrderColumn    = 'page_count'
            , @defragSortOrder      = 'DESC'
            , @excludeMaxPartition  = 1
            , @timeLimit            = NULL
            ,@tableName				= 'dba.dbo.dba_indexDefragExclusion,dba.dbo.dba_indexDefragLog'
            , @database             = 'DBA';


--           
            
EXECUTE dbo.dba_indexDefrag_sp
              @executeSQL           = 1
            , @printCommands        = 1
            , @debugMode            = 1
            , @printFragmentation   = 1
            , @forceRescan          = 1
            , @maxDopRestriction    = 1
            , @minPageCount         = 8
            , @maxPageCount         = NULL
            , @minFragmentation     = 1
            , @rebuildThreshold     = 30
            , @defragDelay          = '00:00:05'
            , @defragOrderColumn    = 'page_count'
            , @defragSortOrder      = 'DESC'
            , @excludeMaxPartition  = 1
            , @timeLimit            = NULL
            ,@tableName				= 'RD_COMMON.dbo.AR_Star_Customer,RD_COMMON.dbo.Sales_Star_Customer'
            , @database             = 'RD_COMMON';
            
            
            
EXECUTE dbo.dba_indexDefrag_sp
              @executeSQL           = 1
            , @printCommands        = 1
            , @debugMode            = 1
            , @printFragmentation   = 1
            , @forceRescan          = 1
            , @maxDopRestriction    = 1
            , @minPageCount         = 8
            , @maxPageCount         = NULL
            , @minFragmentation     = 1
            , @rebuildThreshold     = 30
            , @defragDelay          = '00:00:05'
            , @defragOrderColumn    = 'page_count'
            , @defragSortOrder      = 'DESC'
            , @excludeMaxPartition  = 1
            , @timeLimit            = NULL
            ,@tableName				= 'RD_COMMON.dbo.Star_Dates'
            , @database             = 'RD_COMMON';
            
**/